"""
* 名称：model_load.py
* 功能：测试模型
* 注意：
"""

import torch
from model_train_collision_detection_V2 import DNN

"""********** 加载模型 **********"""
model = torch.load('model_collision_detection_v1.pth')
model.to('cuda:0')

X = [1.55, 0, 0, 0, 0, 0, 0.040, -0.49, 1.16, 0.028983988, -0.272166371, 1.22, -0.013745327, 0.071199894, 1.241997838,
     -0.107642092, -0.195327416, 1.293527722, -0.220300868, -0.3651793, 1.408981323, -0.341132879, -0.499009162,
     1.523368001, 0.149345234, -0.141609564, 1.127255917, 0.274599493, -0.312070817, 1.064984202, 0.323910713,
     -0.395466715, 0.906407595, 0.021285573, -0.113410875, 1.236373544]
# X = X.astype(np.float32)
ts = torch.tensor(X)
ts = ts.to('cuda')
# print(ts.shape)

with torch.no_grad():  # 该局部关闭梯度计算功能
    Pred = model(ts)  # 一次前向传播（批量）
    Pred[Pred >= 0.5] = 1
    Pred[Pred < 0.5] = 0
    pred = int(Pred.item())  # 张量 => int值
    print(f"是否碰撞: {pred}")
